classes = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]


#作业一、根据grade对上述列表进行排序
classes.sort(key=lambda x: x["grade"])
print(classes)


#作业二、通过filter语句来筛选出Grade为A的同学
f = filter(lambda x: x['grade'] == 'A', classes)
f = list(f)
print(f)


#作业三、通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda)
def add(a):
    a["age"] += 1
    return a

m = map(add, classes)
m = list(m)
print(m)


#作业四、使用递归函数重构斐波那契数列
def foo(n):
    if n == 1:
        return 0
    elif n == 2:
        return 1
    else:
        return foo(n-1) + foo(n-2)

for i in range(1, 10):
    print(foo(i))